import React, { Component } from 'react';
import {bindActionCreators} from 'redux';
import * as actions from '../actions/city';
import {connect} from 'react-redux';
import {Redirect} from 'react-router-dom'
class App extends Component {
    
    componentDidMount(){
        this.props.cityActions.initCity({
            cityName:  decodeURIComponent(localStorage.getItem('city')) || "北京"
        })
        
    }
    render() {
        return (
            
            <div>
                <Redirect to="/home"/>
               {
                   this.props.children
               }
            </div>
        );
    }
}

const mapStateToProps = state=>{
    return {
        city : state.city,
        user:state.user.user
    }
}
const mapDispatchToProps = dispatch => {
    return{
        cityActions:bindActionCreators(actions,dispatch)
    }
}
export default connect(mapStateToProps,mapDispatchToProps)(App);